using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Dimok.Data;
using Dimok.Data.Database;

namespace Dimok.Menu.Admin{

	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// <summary>	Work flow tree. </summary>
	///
	/// <remarks>	Dimon, 12/21/2010. </remarks>
	////////////////////////////////////////////////////////////////////////////////////////////////////

	public class WorkFlowTree : System.Web.UI.Page{
		protected Literal ltrWFTree;
		protected Literal ltrActions;
		protected Literal ltrMenus;
		protected HtmlSelect selNSs;
		protected HtmlSelect selGroups;
		protected HtmlSelect selMenus;
		protected HtmlSelect selMenusFrom;
		protected HtmlSelect selMenusTo;

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Event handler. Called by Page for load events. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="sender">	Source of the event. </param>
		/// <param name="e">			Event information. </param>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		private void Page_Load(object sender, System.EventArgs e){
			UserObjectEx uox = new UserObjectEx();
			
			string groupName = UserObjectEx.QueryParam.Get("GroupName");
			if( groupName == "" )groupName = "Admin";
			string statusNameSpace = UserObjectEx.QueryParam.Get("statusNameSpace");
			if( statusNameSpace == "" )statusNameSpace = "";
			SQLHelperEx.SELECT(selNSs,uox.db,"SELECT DISTINCT StatusNameSpace FROM v_Menu_10","StatusNameSpace");
			selNSs.Value = statusNameSpace;
			ltrWFTree.Text = uox.WorkFlowTree(statusNameSpace,groupName);
			if( uox.IsInDomain )SQLHelperEx.SELECT(selGroups,uox.GetAllGroupsInNamespace(),"cn","cn");
			else SQLHelperEx.SELECT(selGroups,uox.db,"SELECT DISTINCT GroupName FROM t_Menu_Group","GroupName");
			selGroups.Items.Add("System");
			selGroups.Value = groupName;

			SQLHelperEx.SELECT(selMenus,uox.WorkFlowList(statusNameSpace),"MenuPath","MenuID");
			DataSet dsWF = uox.WorkFlowList();
			SQLHelperEx.SELECT(selMenusFrom,dsWF,"MenuPath","MenuID",true);
			SQLHelperEx.SELECT(selMenusTo,dsWF,"MenuPath","MenuID",true);

			ltrActions.Text = SQLHelperEx.XmlInnerText(uox.db,uox.MenuEventsSQL(),true);
			ltrMenus.Text = SQLHelperEx.ADOToString(uox.dbADO,"SELECT * FROM t_Menu");
		}

		#region Web Form Designer generated code

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Raises the initialise event. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="e">	Event information to send to registered event handlers. </param>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	
		/// Required method for Designer support - do not modify the contents of this method with the code
		/// editor. 
		/// </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}
